package com.javabasic.algorithm.leetcode;

/**
 * @author xiongmin
 * @version 0.0.1
 * @description Created by work on 2021/11/4 10:03 下午
 * @see [367. Valid Perfect Square](https://leetcode-cn.com/problems/valid-perfect-square/)
 */
public class ValidPerfectSquare {


    /**
     * 利用 long类型加上+暴力二分法
     * @param num
     * @return
     */
    public boolean isPerfectSquare(int num) {
        long left = 1, right = num, mid;
        while (left <= right) {
            System.out.println(left + " " + right);
            mid = left + ((right-left) >> 1);
            if (mid * mid > num) {
                right = mid-1;
            } else if (mid * mid == num) {
                return true;
            } else {
                left = mid + 1;
            }
        }
        return false;
    }

}
